package edu.scau.mis.web.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import edu.scau.mis.cloth.entity.GsUser;
import edu.scau.mis.cloth.entity.Gs_user;
import edu.scau.mis.cloth.service.GsUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (GsUser)表控制层
 *
 * @author makejava
 * @since 2022-05-07 08:25:44
 */
@RestController
@RequestMapping("gsUser")
public class GsUserController {
    /**
     * 服务对象
     */
    @Resource
    private GsUserService gsUserService;
    private boolean state;

    @GetMapping("{userName}/{userPassword}")
    public boolean validate(@PathVariable("userName") String userName,@PathVariable("userPassword")Integer userPassword){
         GsUser user=gsUserService.validate(userName,userPassword);
//         System.out.println(user);
        if(user!=null)
         return true;
        else return false;
    }
    @GetMapping("/returnState")
    public boolean returnState(){
        return state;
    }

    @GetMapping("/queryById/{userId}")
    public List<Map<String,Object>> queryById(@PathVariable("userId")Integer userId){
        return gsUserService.queryById(userId);
    }

    @PutMapping
    public void insert(@RequestBody Gs_user gsUser){
        gsUserService.insert(gsUser);
    }

    @GetMapping("delete/{userId}")
    public void delete(@PathVariable("userId")Integer userId){
        gsUserService.deleteById(userId);
    }

    @PostMapping
    public void update(@RequestBody Gs_user gsUser){
        gsUserService.update(gsUser);
    }

    @GetMapping("/page")
    public PageInfo page(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Map<String,Object>> list = this.gsUserService.queryAll();
        PageInfo<List> pageInfo = new PageInfo(list);
        return pageInfo;
    }
}

